﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Base;
using ERP.BusinessEntities;
using System.Windows.Forms;
using System.IO;
using Core;
using System.Data;

namespace MainApp.Modules.BP
{
    public class BPModule: BaseModule
    {
        public BPModule()
        {
            this.Name = "BP";
            entity = new BPEntity();
            Init();
        }

        public override void Import()
        {
            //OpenFileDialog openFileDlg = new OpenFileDialog();
            //openFileDlg.Multiselect = false;
            //openFileDlg.ShowDialog();

            //String strFileName = openFileDlg.FileName;

            //if (File.Exists(strFileName) == false) return;

            //ExcelClient exClient = new ExcelClient(strFileName);
            //exClient.OpenConnection();
            //String[] lstSheets = exClient.GetSheetName();
            //DataTable dt = exClient.GetAllDataFromSheet(lstSheets[0]);
            //foreach (DataRow dr in dt.Rows)
            //{
            //    try
            //    {
            //        GLBPsInfo BP = new GLBPsInfo();
            //        BP.No = Convert.ToString(dr[0]);
            //        BP.Name = Convert.ToString(dr[3]);
            //        BP.Dsc = BP.Name;
            //        if(dr[4] != null && dr[4] != DBNull.Value)
            //            BP.StartupDate = Convert.ToDateTime(dr[4]);

            //        String strSector = Convert.ToString(dr[5]);
            //        GLBPSectorsInfo Sector = AppContext.BPSectorCtrl.GetObjectByNo(strSector);
            //        if (String.IsNullOrEmpty(strSector) == false)
            //        {
            //            if (Sector == null)
            //            {
            //                Sector = new GLBPSectorsInfo();
            //                Sector.No = strSector;
            //                Sector.Name = strSector;
            //                Sector.Dsc = strSector;

            //                Sector.ID = AppContext.BPSectorCtrl.CreateObject(Sector);
            //            }
            //        }

            //        String strSubSector = Convert.ToString(dr[6]);
            //        GLBPSectorsInfo SubSector = AppContext.BPSectorCtrl.GetObjectByNo(strSubSector);
            //        if (String.IsNullOrEmpty(strSubSector) == false)
            //        {
            //            if (SubSector == null)
            //            {
            //                SubSector = new GLBPSectorsInfo();
            //                SubSector.No = strSubSector;
            //                SubSector.Name = strSubSector;
            //                SubSector.Dsc = strSubSector;
            //                if(Sector != null)
            //                    SubSector.FK_GLBPSectors_ParentID = Sector.ID;
            //                SubSector.ID = AppContext.BPSectorCtrl.CreateObject(SubSector);
            //            }
            //        }

            //        if(SubSector != null)
            //            BP.FK_GLBPSectors_ID = SubSector.ID;

            //        BP.CreatedDate = DateTime.Now;
            //        BP.UpdatedDate = DateTime.Now;


            //        AppContext.BPCtrl.CreateObject(BP);
            //    }
            //    catch (Exception)
            //    {

            //    }


        }

    }
}
